home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / tools / dcview / src / dctxt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-22  |  11.8 KB  |  477 lines

  1. /******************************************************************************
  2.  *    DCtxt.c:    テキスト表示処理
  3.  ******************************************************************************
  4.  *
  5.  *
  6.  */
  7. #include <sxdef2.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <io.h>
  12. #include <jfctype.h>
  13. #include <doslib.h>
  14. #include <event.h>        /* イベントマンを利用するときに必要    */
  15. #include <sxgraph.h>        /* グラフ系マネージャを利用するときに必要 */
  16. #include <window.h>        /* ウィンドウマンを利用するときに必要    */
  17. #include <dialog.h>        /* ダイアログマンを利用するときに必要    */
  18. #include <task.h>        /* タスクマンを利用するときに必要    */
  19. #include "DC.h"            /* このプログラム固有のヘッダファイル    */
  20.  
  21. /******************************************************************************
  22.  *    drawtxt():    テキストの描画
  23.  ******************************************************************************
  24.  *    引数:    ComVal *pcv    共通変数へのポインタ
  25.  *        int    part    0:部分書きかえ
  26.  *                1:全画面書きかえ    
  27.  */
  28. void drawtxt(ComVal *pcv, int part)
  29. {
  30.     int i,j,jj,k,tb,vw,drawPt,end,esc;
  31.     char buff[100];
  32.     char buff2[100];
  33.     char dmyfname[100];
  34.     char *txtPt;
  35.     int *txtNo;
  36.     int pat1,pat2;
  37.     int line_no;
  38.     int cut_no;
  39.     int cut_lno,ylen;
  40.     int zen;
  41.     Rect cut_rc_src;
  42.     Rect cut_rc_dst;
  43.     LPoint ppos;
  44.     Region **curRgn;
  45.     Rect rc = { 0, 0, 0, 0};
  46.     
  47.     rc.d.right  = pcv->win_h;
  48.     rc.d.bottom = pcv->win_v - 20;
  49.  
  50.     if (pcv->loadFlag == 0)
  51.         return;
  52.  
  53.     GMSetGraph(&pcv->windowPtr->graph);
  54.     GMFontKind(pcv->fontK[pcv->font]);
  55.     GMFontSize(LONGWORD(pcv->fontS[pcv->font],pcv->fontS[pcv->font]));
  56.     GMForeColor(pcv->fore_color);
  57.     GMBackColor(pcv->back_color);
  58.  
  59.     GMSetClip(pcv->txtRgnHdl);
  60.  
  61.     MMHdlLock(pcv->txt);    /* テキストのハンドルをロック    */
  62.     MMHdlLock(pcv->txtNo);
  63.  
  64.     txtPt = *(pcv->txt);
  65.     txtNo = *(pcv->txtNo);
  66.  
  67.     if (part != 0) {
  68.         if (pcv->scrollDir > 0) {    /* テキストスクロール    */
  69.             GMScroll(&rc, LONGWORD(0,-pcv->fontS[pcv->font] * pcv->scrollstep), pcv->updateRgnHdl);
  70.             end = pcv->scrollstep + 1;
  71.             drawPt = (29 - pcv->scrollstep) * pcv->fontS[pcv->font];
  72.             line_no = pcv->ofset + 29 - pcv->scrollstep;
  73.             txtPt = txtPt + *(txtNo + line_no);
  74.         } else {            /* テキスト逆スクロール    */
  75.             GMScroll(&rc, LONGWORD(0, pcv->fontS[pcv->font] * pcv->scrollstep), pcv->updateRgnHdl);
  76.             end = pcv->scrollstep + 1;
  77.             drawPt = 0;
  78.             line_no = pcv->ofset;
  79.             txtPt = txtPt + *(txtNo + pcv->ofset);
  80.         }
  81.     } else {                /* 全テキスト表示    */
  82.         GMForeColor(pcv->back_color);
  83.         GMFillRect(&rc);
  84.         GMForeColor(pcv->fore_color);
  85.             end = 30;
  86.         drawPt = 0;
  87.         line_no = pcv->ofset;
  88.         txtPt = txtPt + *(txtNo + pcv->ofset);
  89.     }
  90.  
  91.     for(i=0;i<end;i++) {            /* テキスト描画        */
  92.         if (pcv->Maxline < (line_no + i)) break;
  93.         j = 0;
  94.         jj = 0;
  95.         vw = 0;
  96.         pcv->pre_esc = 33;
  97.         zen = 1;
  98.         GMMove(LONGWORD(0,drawPt + i * pcv->fontS[pcv->font]));
  99.         while(1) {
  100.             if (*txtPt == 13) {            /* 改行処理    */
  101.                 buff[j] = 0;
  102.                 txtPt++;
  103.                 break;
  104.             }
  105.  
  106.             if (*txtPt == 10) {            /* LF処理    */
  107.                 txtPt++;
  108.                 continue;
  109.             }
  110.  
  111.             if (*txtPt == 9) {            /* TAB処理    */
  112.                 tb = 8 - (jj % 8);
  113.                 buff[j] = 0;
  114.                 if (j > 0)
  115.                     GMDrawStrZ(buff);
  116.                 GMMoveRel(LONGWORD(tb * pcv->fontS[pcv->font] / 2, 0));
  117.                 j = 0;
  118.                 jj = jj + tb;
  119.                 txtPt++;
  120.                 zen = 0;
  121.                 continue;
  122.             }
  123.  
  124.             if (*txtPt ==  27) {            /* esc文字属性    */
  125.                 if (*(txtPt+1) == '[') {
  126.                     buff2[0] = 0;
  127.                     esc = 0;
  128.                     txtPt++;
  129.                     txtPt++;
  130.                     while(*txtPt != 'm' && *txtPt != 'C') {
  131.                         buff2[esc++] = *(txtPt++);
  132.                     }
  133.                     if (esc != 0) {
  134.                         if (*txtPt == 'C') {
  135.                             buff2[esc] = 0;
  136.                             esc = atoi(buff2);
  137.                             GMMoveRel(LONGWORD(esc*pcv->fontS[pcv->font]/2, 0));
  138.                             txtPt++;
  139.                             j = 0;
  140.                             continue;
  141.                         }
  142.                         buff2[esc] = 0;
  143.                         esc = atoi(buff2);
  144.                         buff[j] = 0;
  145.                         GMDrawStrZ(buff);
  146.  
  147.                         esc_mode(pcv, esc);
  148.  
  149.                         txtPt++;
  150.                         j = 0;
  151.                         continue;
  152.                     } else {
  153.                         buff[j] = 0;
  154.                         GMDrawStrZ(buff);
  155.  
  156.                         esc_mode(pcv, 0);
  157.  
  158.                         txtPt++;
  159.                         j = 0;
  160.                         continue;
  161.                     }
  162.                 }
  163.             }
  164.  
  165.             if (jj == 94){            /* 行の折り返し    */
  166.                 if (adjust(txtPt)) {
  167.                     buff[j++] = *txtPt++;
  168.                     buff[j++] = *txtPt++;
  169.                 }
  170.                 if (*txtPt == 13)
  171.                     txtPt++;
  172.                 buff[j] = 0;
  173.                 break;
  174.             }
  175.             if (jj > 94) {
  176.                 buff[j] = 0;
  177.                 break;
  178.             }
  179.  
  180.             pat1 = (int)*txtPt & 0xff;
  181.             if (iskanji(pat1)) {            /* 漢字        */
  182.                 buff[j++] = *txtPt++;
  183.                 buff[j++] = *txtPt++;
  184.                 jj += 2;
  185.                 continue;
  186.             }
  187.  
  188.             if (*txtPt ==  '%') {            /* %コード処理    */
  189.                 if (*(txtPt + 1) == 'V') {    /* 倍角設定    */
  190.                     vw = 1;
  191.                     txtPt = txtPt + 4;
  192.                     buff[j] = 0;
  193.                     GMDrawStrZ(buff);
  194.                     j = 0;
  195.                     continue;
  196.                 }
  197.                 if ((*(txtPt + 1) == 'C') && (*(txtPt+2) != 'U')) { /* カットファイル  */
  198.                     cut_no = *(txtPt+2) - '0';
  199.                     cut_lno = *(txtPt+3) - '0';
  200.                     if (*(txtPt+4)==':') {
  201.                         while(*txtPt++ != '.') {
  202.                         }
  203.                         txtPt = txtPt + 3;
  204.                     } else {
  205.                         txtPt = txtPt + 4;
  206.                     }
  207.                     if (j>0) {
  208.                         buff[j] = 0;
  209.                         GMDrawStrZ(buff);
  210.                         j = 0;
  211.                     }
  212.  
  213.                     GMLockBits(pcv->bitsH[cut_no][pcv->depth]);
  214.                     pcv->offgraph[cut_no][pcv->depth].bmap = &(*pcv->bitsH[cut_no][pcv->depth])->bmap;
  215.  
  216.                     cut_rc_src.d.top = cut_lno * pcv->fontS[pcv->font];
  217.                     cut_rc_src.d.right = pcv->offgraph[cut_no][pcv->depth].rect.d.right;
  218.                     if (cut_rc_src.d.top + pcv->fontS[pcv->font] > pcv->offgraph[cut_no][pcv->depth].rect.d.bottom) {
  219.                         cut_rc_src.d.bottom = pcv->offgraph[cut_no][pcv->depth].rect.d.bottom;
  220.                         ylen = cut_rc_src.d.bottom - cut_rc_src.d.top;
  221.                     } else {    
  222.                         cut_rc_src.d.bottom = cut_rc_src.d.top + pcv->fontS[pcv->font];
  223.                         ylen = pcv->fontS[pcv->font];
  224.                     }    
  225.                     cut_rc_src.d.left = 0;
  226.  
  227.                     ppos = GMGetLoc();
  228.                     cut_rc_dst.d.top = LOWWORD(ppos);
  229.                     cut_rc_dst.d.right = HIWORD(ppos) + cut_rc_src.d.right;
  230.                     cut_rc_dst.d.bottom = cut_rc_dst.d.top + ylen;
  231.                     cut_rc_dst.d.left = HIWORD(ppos);
  232.  
  233.                     GMCopy(&(*pcv->bitsH[cut_no][pcv->depth])->bmap, pcv->windowPtr->graph.bmap,
  234.                         &cut_rc_src, &cut_rc_dst,
  235.                             G_PSET, NULL);  /* pcv->windowPtr->update); */
  236.                     GMUnlockBits(pcv->bitsH[cut_no][pcv->depth]);
  237.                     GMMoveRel(LONGWORD(cut_rc_src.d.right,0));
  238.                     continue;
  239.                 }
  240.             }
  241.  
  242.             if (*txtPt ==  24) {            /* 倍角解除    */
  243.                 if (vw == 1) {
  244.                     esc_mode(pcv, 0);
  245.                     buff[j] = 0;
  246.                     GMFontKind(pcv->fontK[pcv->font] + 1);
  247.                     GMFontSize(LONGWORD(pcv->fontL[pcv->font],pcv->fontL[pcv->font]));
  248.                     GMMoveRel(LONGWORD(0,4));
  249.                     GMDrawStrZ(buff);
  250.                     GMFontKind(pcv->fontK[pcv->font]);
  251.                     GMFontSize(LONGWORD(pcv->fontS[pcv->font],pcv->fontS[pcv->font]));
  252.                     GMMoveRel(LONGWORD(0,-4));
  253.                     vw = 0;
  254.                     jj = jj + j / 2;
  255.                     if (pcv->font == 0)
  256.                         GMMove(LONGWORD(jj * pcv->fontS[pcv->font] / 2,
  257.                             drawPt + i * pcv->fontS[pcv->font]));
  258.                     j = 0;
  259.                     txtPt++;
  260.                     continue;
  261.                 }
  262.                 txtPt++;
  263.                 continue;
  264.             }
  265.  
  266.             buff[j++] = *(txtPt++);
  267.             buff[j] = 0;
  268.  
  269.             jj++;
  270.         }
  271.  
  272.         if (vw) {
  273.             GMFontKind(pcv->fontK[pcv->font] + 1);
  274.             GMFontSize(LONGWORD(pcv->fontL[pcv->font],pcv->fontL[pcv->font]));
  275.             GMMoveRel(LONGWORD(0, 4));
  276.             }
  277.         GMDrawStrZ(buff);
  278.         if (vw) {
  279.             GMFontKind(pcv->fontK[pcv->font]);
  280.             GMFontSize(LONGWORD(pcv->fontS[pcv->font],pcv->fontS[pcv->font]));
  281.             GMMoveRel(LONGWORD(0, -4));
  282.             vw = 0;
  283.         }
  284.         pcv->pre_esc = 33;
  285.         esc_mode(pcv, 33);
  286.     }
  287.     MMHdlUnlock(pcv->txtNo);    /* テキストのハンドルをアンロック */
  288.     MMHdlUnlock(pcv->txt);
  289.     GMSetClip(pcv->winRgnHdl);
  290.     CMValueSet(pcv->volHdl, pcv->ofset);
  291.     if (!pcv->lineDisp) {        /* 行番号表示            */
  292.         GMShadowRect(&pcv->rcl);
  293.         GMMove(pcv->lxy.x_y);
  294.         sprintf(buff, "%5d", pcv->ofset + 1);
  295.         GMFontKind(G_ROM12);
  296.         GMFontSize(LONGWORD(12,12));
  297.         GMDrawStrZ(buff);
  298.     }
  299. }
  300.  
  301. /******************************************************************************
  302.  *    esc_mode():    テキストの描画モード変更処理
  303.  ******************************************************************************
  304.  *    引数:    ComVal *pcv    共通変数へのポインタ
  305.  *        int    esc    描画モード
  306.  */
  307. int esc_mode(ComVal *pcv, int esc)
  308. {
  309.     int esc_color, pre_esc_color;
  310.     int esc_mode, pre_esc_mode;
  311.  
  312.     GMSetGraph(&pcv->windowPtr->graph);
  313.     if (esc == 0) 
  314.         esc = 33;
  315.  
  316.     pre_esc_color = (pcv->pre_esc % 10) % 4;
  317.     pre_esc_mode = pcv->pre_esc;
  318.     esc_color = (esc % 10) % 4;
  319.     esc_mode = esc;
  320.  
  321.     if (esc == 1) {
  322.         if (pre_esc_mode < 34)
  323.             esc_mode = pre_esc_mode + 4;
  324.         if (pre_esc_mode > 43)
  325.             esc_mode = pre_esc_mode - 4;
  326.         esc_color = pre_esc_color;
  327.     }
  328.     if (esc == 7) {
  329.         if (pre_esc_mode < 38)
  330.             esc_mode = pre_esc_mode + 10;
  331.         if (pre_esc_mode > 39)
  332.             esc_mode = pre_esc_mode - 10;
  333.         esc_color = pre_esc_color;
  334.     }
  335.  
  336.     switch(esc_color) {
  337.         case 0:    GMForeColor(pcv->back_color);
  338.             break;
  339.         case 1:    GMForeColor(G_BLUE);
  340.             break;
  341.         case 2:    GMForeColor(G_RED);
  342.             break;
  343.         case 3:    GMForeColor(pcv->fore_color);
  344.             break;
  345.     }
  346.  
  347.     if (esc_mode < 34) {
  348.         GMFontMode(G_PSET);
  349.         GMFontFace(G_PLANE);
  350.         GMFontSize(LONGWORD(pcv->fontS[pcv->font],pcv->fontS[pcv->font]));
  351.     return (esc);
  352.     }
  353.     if (esc_mode < 38) {
  354.         GMFontMode(G_PSET);
  355.         GMFontFace(G_BOLD);
  356.         GMFontSize(LONGWORD(pcv->fontS[pcv->font] - 1,pcv->fontS[pcv->font]));
  357.     return (esc);
  358.     }
  359.     if (esc_mode < 44) {
  360.         GMFontMode(G_NXOR);
  361.         GMFontFace(G_PLANE);
  362.         GMFontSize(LONGWORD(pcv->fontS[pcv->font],pcv->fontS[pcv->font]));
  363.     return (esc);
  364.     }
  365.     if (esc_mode < 34) {
  366.         GMFontMode(G_NXOR);
  367.         GMFontFace(G_BOLD);
  368.         GMFontSize(LONGWORD(pcv->fontS[pcv->font] - 1,pcv->fontS[pcv->font]));
  369.     return (esc);
  370.     }
  371.  
  372.     return(esc);
  373. }
  374.  
  375. /******************************************************************************
  376.  *    scrollTxt():    テキストのスクロール処理
  377.  ******************************************************************************
  378.  *    引数:    ComVal *pcv    共通変数へのポインタ
  379.  *        int    part     1:上スクロール
  380.  *                -1:下スクロール    
  381.  */
  382. int scrollTxt(ComVal *pcv, int dir)
  383. {
  384.     int sclbuff;
  385.     pcv->scrollDir = dir;
  386.  
  387.     if (pcv->loadFlag == 0)
  388.         return;
  389.  
  390.     if (dir > 0) {
  391.         if (pcv->ofset < (pcv->Maxline - 29)) {
  392.             pcv->ofset = pcv->ofset + pcv->scrollstep;
  393.             drawtxt(pcv, 1); /* ウィンドウ内部を描画する    */
  394.             return (1);
  395.         }
  396.     } else {
  397.         if (pcv->ofset > 0) {
  398.             pcv->ofset = pcv->ofset - pcv->scrollstep;
  399.             if ((pcv->ofset - pcv->scrollstep) < 0) {
  400.                 sclbuff = pcv->scrollstep;
  401.                 pcv->scrollstep = pcv->scrollstep + pcv->ofset;
  402.                 pcv->ofset = 0;
  403.                 drawtxt(pcv, 1); /* ウィンドウ内部を描画する    */
  404.                 pcv->scrollstep = sclbuff;
  405.             } else {
  406.                 drawtxt(pcv, 1); /* ウィンドウ内部を描画する    */
  407.             }
  408.             return (1);
  409.         }
  410.     }
  411.     return (0);
  412. }
  413.  
  414. /******************************************************************************
  415.  *    adjust():    いいかげんな禁則処理
  416.  ******************************************************************************
  417.  *    引数:    char   *txtPt
  418.  */
  419. int adjust(char *txtPt)
  420. {
  421.     int pat, ret;
  422.  
  423.     pat = ((((int)*txtPt) << 8) + (int)*(txtPt+1)) & 0xffff;
  424.     switch(pat) {
  425.         case L'ぁ':
  426.         case L'ぃ':
  427.         case L'ぅ':
  428.         case L'ぇ':
  429.         case L'ぉ':
  430.         case L'ァ':
  431.         case L'ィ':
  432.         case L'ゥ':
  433.         case L'ェ':
  434.         case L'ォ':
  435.         case L'ゃ':
  436.         case L'ゅ':
  437.         case L'ょ':
  438.         case L'ゎ':
  439.         case L'っ':
  440.         case L'ャ':
  441.         case L'ュ':
  442.         case L'ョ':
  443.         case L'ヮ':
  444.         case L'ッ':
  445.  
  446.         case L'、':
  447.         case L'。':
  448.         case L',':
  449.         case L'.':
  450.         case L'?':
  451.         case L'!':
  452.         case L'゛':
  453.         case L'´':
  454.         case L'`':
  455.         case L'‘':
  456.         case L'“':
  457.         case L')':
  458.         case L'〕':
  459.         case L']':
  460.         case L'}':
  461.         case L'〉':
  462.         case L'》':
  463.         case L'」':
  464.         case L'』':
  465.         case L'】':
  466.         case L'>':
  467.             ret = 1;
  468.             break;
  469.         default:
  470.             ret = 0;
  471.             break;
  472.     }
  473.     return(ret);
  474. }
  475. STR@-ムEdEV3.00<@(!%G0JHH     
  476. ;7\7
  477. 6W^コマ Z@ "    (.Ohh$000ヨ=STL@ロL